<?php
/**
 * @file test010.php
 * @package taobaoke
 * @subpackage 
 * @version $id: 0.1 UTF-8 2009-7-19 下午08:39:52 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * 获取SessionKey的容器地址：http://container.open.taobao.com/container?appkey=12001409 
 * 测试数据获取完整性！ 
 * 
 * http://my.donews.com/ak47/2006/08/03/QMJitGhMEbHXEUGQPdxRfhPUTybKBgynafUZ/
 * Wordpress的XMLrpc
 * 
 * 插入Post
 * http://codex.wordpress.org/Function_Reference/wp_insert_post
 */

header("Content-Type:text/html;charset=UTF-8");
require_once '../lib/functions.php';

$session = trim($_GET['top_session']);
echo "Everything begin with <span style=\"color:yellow\">".$session."</span><br />\t\n";
//refurbishTaobaoCats($session);
//echo "<br /><span style=\"color:green\">淘宝分类更新完成...</span>...";

/*joinTaobaoke($session,array('method' => 'keyword', 
										'key' => '情侣',
										'sort' => 'default',
										'page_size' => 15));*/

$dbh = new tbkDB();
//var_dump($dbh->getItemsIid());
//var_dump($dbh->getItemInfo('cc2466ef05b2400239f5ac7eaeff9f8b'));
//$item = $dbh->getItemInfo('cc00f57628af11c51966d9a93227e169');

foreach ($dbh->getItemsIid() as $ID){
	$item = $dbh->getItemInfo($ID['iid']);



//标题
echo "\n\t<br /><hr /><br /><span style=\"color:green\">标题</span>: ".$item['title'].' - '.$item['cid'];

//关键字
$keywords = array();
$key1 = array();
$key2 = preg_split('/&nbsp;|:|;/', $item['properties'],  -1, PREG_SPLIT_NO_EMPTY);
preg_match('/.*<span class=H>(.*)<\/span>.*/', $item['title'], $key1, PREG_OFFSET_CAPTURE);
//$key1 = preg_split('/.*<span class=H>|<\/span>.*/', $item['title'],  -1, PREG_SPLIT_NO_EMPTY);
//var_dump($key1);

if(!empty($key1)) array_unshift($keywords, $key1[1][0]);
for ($i=1; $i<count($key2); $i += 2){
	array_push($keywords, $key2[$i]);
}
$j = count($keywords) - 5;
if($j>0){
	for ($i=0; $i<$j; $i++)
		array_pop($keywords);
}
array_push($keywords, $item['cid']);
$step1 = array ("(", ")", "[", "]", "?", ".", "/", "|", "\$", "*", "+", "^", "{", "}" );
$wp_slug = hm_tranlate($keywords[0]);
$artarray = str_replace ( $step1, ",", implode(',', $keywords) );
echo "\n\t<br /><span style=\"color:green\">关键字</span>: ".$artarray.' -slug- '.$wp_slug;

// 摘要 注意title2可能为空
$ex = preg_split('/\s|：|，|；|（|）|(&nbsp;)/', $item['title2'].' '.$item['desc'], -1, PREG_SPLIT_NO_EMPTY);
$ex = array_unique($ex); //去除重复关键字
$mt_excerpt = implode(' ', $ex); //合并
$mt_excerpt = $item['price'].'元的'.$mt_excerpt;
if (utf8_strlen($mt_excerpt) > 110)
	$mt_excerpt = utf8_trim(substr($mt_excerpt,0,220));
echo "\n\t<br /><span style=\"color:green\">摘要</span>: ".$mt_excerpt;
	
	
}//foreach ($dbh->getItemsIid() as $ID)


/*$dbh = new tbkDB();

$string = "<img src=\"http://img06.taobaocdn.com/bao/uploaded/i6/T1DANjXiSnudNXw63Z_033130.jpg\" alt=\"冲钻特价！个性挑逗扣伴衬衫领情侣 POLO 短袖T恤 四色款\" />";
echo $string."<br /><hr /><br />";
var_dump($string);

$item = getTaobaokeItems($session, array('method' => 'keyword', 
										'key' => '雪纺',
										'sort' => 'default',
										'page_size' => 15));
$item = getTaobaokeItems($session, array('method' => 'cid', 
										'key' => '1512',
										'sort' => 'default',
										'page_size' => 15));

for($i=0; $i<count($item); $i++){
	
	if ($dbh->isExist($item[$i]['iid'], 'items'))
		continue;
	
	$item2 = getTaobaoItem($session, $item[$i]['nick'],$item[$i]['iid']);
	$itemArray = array(
		'iid' => $item[$i]['iid'],
		'title' => $item[$i]['title'],
		'pic_url' => $item[$i]['pic_url'],
		'price' => $item[$i]['price'],
		'click_url' => $item[$i]['click_url'],
		'nick' => $item[$i]['nick'],
		'commission' => $item[$i]['commission'],
		'commission_rate' => $item[$i]['commission_rate'],
		'commission_num' => $item[$i]['commission_num'],
		'commission_volume' => $item[$i]['commission_volume'],
		'cid' => $item2['cid'],
		'title2' => $item2['title2'],
		'location' => $item2['location'],
		'properties' => $item2['properties'],
		'desc' => $item2['desc']
	);
	$dbh->inItem($itemArray);
	echo "<br /><span style=\"color:blue\">入库:</span> ".$item[$i]['title'];
	//var_dump($itemArray);
	
	$shop = getTaobaokeShop($session,$item[$i]['nick']);
	if ($dbh->isExist($shop['user_id'],'shops'))
		continue;
	
	$shopArray = array(
		'user_id' => $shop['user_id'],
		'nick' => $shop['nick'],
		'credit' => $shop['credit'],
		'sex' => $shop['sex'],
		'sid' => $shop['sid'],
		'title' => $shop['title'],
		'desc' => $shop['desc'],
		'created' => $shop['created'],
		'click_url' => $shop['click_url'],
		'shop_commission.rate' => $shop['shop_commission.rate']
	);
	$dbh->inShop($shopArray);
	echo " <span style=\"color:blue\">+店主:</span> ".$shop['nick'];
}*/



?>